#include "tcuException.h"
#include "tcuCommunication.h"
#include "ChargeCtrl.h"
#include "inputCtl.h"
#include "outputctl.h"

extern tcuParameterConfigRcv gtcuParameterConfigRcv[GUNNUM_MAX];

extern remoteInformation gremoteInformation[GUNNUM_MAX];



//input signal feedback: Emergency Stop Switch
void exceptionEmergencyStopStatus(uint8_t rsv)
{
	gremoteInformation[GUNA].emergencyStop = !getShortPressSignal(EMERGENCYSTOP_STATUS);
	gremoteInformation[GUNB].emergencyStop = !getShortPressSignal(EMERGENCYSTOP_STATUS);
}

//input signal feedback: AC Contactor
void exceptionAcContactStatus(uint8_t connectorId)
{
	getShortPressSignal(AC_CONTACT_STATUS);
}

//input signal feedback: AC Breaker 
void exceptionBreakStatus(uint8_t connectorId)
{
	getShortPressSignal(AC_BREAK_STATUS);
}

//input signal feedback: Surge Procective Device
void exceptionSurgeProtectionStatus(uint8_t connectorId)
{
	getShortPressSignal(LIGHTNINGARRESTER_STATUS);
}

//input signal feedback: Fan
void exceptionFanStatus(uint8_t connectorId)
{
	getShortPressSignal(FANFEEDBACK_STATUS);
}


//input signal feedback: Access Control Switch 
void exceptionAccessControlSwitchStatus(uint8_t connectorId)
{
	getShortPressSignal(ACCESSCONTROLSWITCH_STATUS);
}

//input signal feedback: Smoke Sensor
void exceptionSmokeSensorStatus(uint8_t connectorId)
{
	getShortPressSignal(SMOKESENSOR_STATUS);
}

//input signal feedback: A Connector DC Relay1
void exceptionAgunDcRealsy1Status(uint8_t connectorId)
{
	getShortPressSignal(AGUNDCCONTACTFIRST_STATUS);
}

//input signal feedback: A Connector DC Relay2
void exceptionAgunDcRealsy2Status(uint8_t connectorId)
{
	getShortPressSignal(AGUNDCCONTACTSECOND_STATUS);
}

//input signal feedback: A Connector DC Relay3
void exceptionAgunDcRealsy3Status(uint8_t connectorId)
{
	getShortPressSignal(AGUNDCCONTACTTHIRD_STATUS);
}
//input signal feedback: A Connector Electronic Lock
void exceptionAgunElectronicLockStatus(uint8_t connectorId)
{	
	if(gtcuParameterConfigRcv[connectorId].electronicLock == LOCK_POSITIVE_FEEDBACK)	//exist electronic lock with positive feedback
	{
		gremoteInformation[connectorId].electronicLockFault = getShortPressSignal(connectorId==GUNA? AGUNELECTRONICLOCK_STATUS: BGUNELECTRONICLOCK_STATUS);
	}
	else if(gtcuParameterConfigRcv[connectorId].electronicLock == LOCK_NEGATIVE_FEEDBACK)//exist electronic lock with negative feedback
	{
		gremoteInformation[connectorId].electronicLockFault = !getShortPressSignal(connectorId==GUNA? AGUNELECTRONICLOCK_STATUS: BGUNELECTRONICLOCK_STATUS);
	}
	else if(gtcuParameterConfigRcv[connectorId].electronicLock == LOCK_DISABLE_FEEDBACK)
	{
		gremoteInformation[connectorId].electronicLockFault = 0;
	}
	else if(gtcuParameterConfigRcv[connectorId].electronicLock == NO_LOCK_NO_FEEDBACK)
	{
		gremoteInformation[connectorId].electronicLockFault = 0;
	}
}
//input signal feedback: A Connector DC Fuse
void exceptionAgunDcFuseStatus(uint8_t connectorId)
{	
	getShortPressSignal(AGUNDCCONTACTFUSES_STATUS);
}
//input signal feedback: B Connector DC Relay1
void exceptionBgunDcRealsy1Status(uint8_t connectorId)
{	
	getShortPressSignal(BGUNDCCONTACTFIRST_STATUS);
}
//input signal feedback: B Connector DC Relay2
void exceptionBgunDcRealsy2Status(uint8_t connectorId)
{	
	getShortPressSignal(BGUNDCCONTACTSECOND_STATUS);
}
//input signal feedback: B Connector DC Relay3
void exceptionBgunDcRealsy3Status(uint8_t connectorId)
{	
	getShortPressSignal(BGUNDCCONTACTTHIRD_STATUS);
}
//input signal feedback: B Connector Electronic Lock
void exceptionBgunElectronicLockStatus(uint8_t connectorId)
{	
	getShortPressSignal(BGUNELECTRONICLOCK_STATUS);
}
//input signal feedback: B Connector DC Fuse
void exceptionBgunFuseStatus(uint8_t connectorId)
{
	getShortPressSignal(BGUNDCCONTACTFUSES_STATUS);
}

typedef void (*exceptionPtr)(uint8_t );


exceptionPtr ExceptionFunction[] = 
{
	exceptionEmergencyStopStatus,
	exceptionAcContactStatus,
	exceptionBreakStatus,
	exceptionSurgeProtectionStatus,
	exceptionFanStatus,
	exceptionAccessControlSwitchStatus,
	exceptionSmokeSensorStatus,
	exceptionAgunDcRealsy1Status,
	exceptionAgunDcRealsy2Status,
	exceptionAgunDcRealsy3Status,
	exceptionAgunElectronicLockStatus,
	exceptionAgunDcFuseStatus,
	exceptionBgunDcRealsy1Status,
	exceptionBgunDcRealsy2Status,
	exceptionBgunDcRealsy3Status,
	exceptionBgunElectronicLockStatus,
	exceptionBgunFuseStatus,
};


void getExceptionStatus(void)
{
	uint8_t i;
	
	for (i = 0; i < sizeof(ExceptionFunction)/sizeof(exceptionPtr); i++) 
	{
		ExceptionFunction[i](i);
	}
	
}



